{extend name="base"}
{block name="title"}渠道查询{/block}
{block name="head"}
<style>
.border-table{font-size:12px; color:#666;}
</style>
{/block}
{block name="body"}
<body class="mainbody">
<form>
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>渠道查询</span>
</div>

<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
      </div>
      <div class="r-list">
        <a class="input">创建新的渠道</a>
      </div>
    </div>
    
  </div>
</div>          

<div class="table-container" >
  <table class="border-table">
    <thead>
      <tr>
        <th></th>
        <th colspan="2">渠道</th>
        <th colspan="4">房卡</th>
        <th colspan="2">时间</th>
        <th colspan="4">金币</th>
        <th colspan="3">关联数</th>
        <th rowspan="2">更新记录</th>
        <th rowspan="2">状态</th>
        <th rowspan="2">操作</th>
       
       

      </tr>
      <tr>
        <th>#</th>
        <th>渠道标识</th>
        <th>渠道版本</th>
        <th>注册</th>
        <th>实名</th>
        <th>分享</th>
        <th>绑定</th>
        <th>创建时间</th>
        <th>更新时间</th>
        <th>注册金币</th>
        <th>实名金币</th>
        <th>分享金币</th>
        <th>绑定金币</th>
        <th>关联玩家</th>
        <th>关联代理</th>
        <th>关联游戏</th>

      </tr>
    </thead>
    <tbody>
{empty name="list"}
      <tr><td colspan="13">Oh~暂无数据!</td></tr>
{else/}
    {volist name="list" id="v"}
    <tr data-id="{$v.ID}">
      <td>{$v.ROW_NUMBER}</td>
      <td style="text-align: left;">[{$v.ID}]{$v.Name}</td>
      <td>{$v.Version}</td>
      <td>{$v.ZCRoomCard*1}</td>
      <td>{$v.SMRoomCard*1}</td>
      <td>{$v.FXRoomCard*1}</td>
      <td>{$v.BDRoomCard*1}</td>
      <td>{$v.CreateTime}</td>
      <td>{$v.UpdateTime}</td>
      <td>{$v.ZCGold*1}</td>
      <td>{$v.SMGold*1}</td>
      <td>{$v.FXGold*1}</td>
      <td>{$v.BDGold*1}</td>
      <td>{$v.TotalPlayer}</td>
      <td>{$v.TotalAgent}</td>
      <td>{$v.TotalGame}</td>
      <td><a target="_blank" href="{:url('system.channel.version/index')}?channel={$v.ID}">{$v.TotalVersion}</a></td>
      <td style="color:{gt name='v.State' value='0'}green{else}red{/gt}" title="{$v.State}">{gt name='v.State' value='0'}启用{else}禁用{/gt}</td>
      <td>
        <input type="button" class="a" value="修改" />
        <input type="button" class="serconfig" value="网络配置" />
        <input type="button" class="delchan" value="删除" />
      </td>
    </tr>
    {/volist}
{/empty}
    </tbody>
  </table>
</div>

<div class="page-footer"><div class="btn-wrap">{$list->render()}</div></div>

<script>
$.extend({
  ChannelConfig: {
    ShowDetailDialog: function (id) {

      var url = "{:url('detail')}?id=" + id;
      dialog($.extend({
          title: '详情[' + id + ']',
          url: url,
          width: 820,
          height: 530,
          okValue: '确认提交',
          ok: function () {
            var f = $('iframe', this.node);
            var v = $('form', f.contents()).serialize();
            console.log(f);
            console.log(v);
            $.post(url, v, function (resp, state, xhr) {
              console.log(resp);
              alert(resp.error);
              if (resp.errno == 0) {
                location.reload();
              }
            });
            return false;
          }
        }, id > 0 ? {
          button: [{
              value: '删除规则',
              autofocus: true,
              callback: function () {
                $.SystemMsg.ShowDeleteConfirm(id);
                return false;
              }
            }
          ]
        } : {})).showModal();
    },
    ShowDeleteConfirm: function (id) {
      dialog({
        title: '提示',
        content: '确定删除?id=' + id,
        width: 200,
        height: 30,
        okValue: '确认',
        ok: function () {
          var url = "{:url('delchannel')}?id=" + id;
          $.post(url, function (resp, state, xhr) {
            console.log(resp);
            alert(resp.error);
            if (resp.errno == 0) {
              location.reload();
            }
          });
          return false;
        }
      }).showModal();
    }
  }
});

$(function() {
  $('.toolbar a.input').click(function () { // 新建
    $.ChannelConfig.ShowDetailDialog(0);
  });
  $('input.a').click(function () {  // 修改
    var id = $(this).parents('tr').attr('data-id');
    $.ChannelConfig.ShowDetailDialog(id);
  });
  $('input.delchan').click(function () {  // 删除
    var id = $(this).parents('tr').attr('data-id');
    $.ChannelConfig.ShowDeleteConfirm(id);
  });
  $(".srvc").live('click',function(){
        var srv = $(this).attr('srv');
        var thiskey = $(this).parents('dl').children().last().attr('key');
        var key =Number(thiskey)+1;
        // if (key != )
        // console.log(key)

        var a = '<dd srv="'+srv+'" key="'+key+'">' +
            'ServerIP['+key+']：<input type="text" width="100" class="input big" autocomplete="off" name="Srv'+srv+'IP'+key+'" value="" />' +
            '<span style="padding-left: 16px;">' +
            'Server端口['+key+']：<input type="text" class="input small" autocomplete="off" name="Srv'+srv+'Ad'+key+'" value="" />'+
            '           </span><a href="javascript:;"><i class="iconfont icon-add srvc" srv="'+srv+'" title="增加"></i></a>' +
            '           <a href="javascript:;"><i class="iconfont icon-remove delS" srv="'+srv+'" key="'+key+'" title="删除"></i></a>' +
            '</dd>';
        $(this).parents("dl").children().last().after(a);

    });

$(".icon-remove").live('click',function() {
    $(this).parents('dd').remove();
});
$('input.serconfig').click(function () {  // 网络配置详情修改
    var id = $(this).parents('tr').data('id');
    var url = "{:url('srvdetail')}?id=" + id;
    dialog({
      title: '渠道[' + id + ']详情',
      url: url,
      width: 820,
      height: 550,
      okValue: '确定',
      cancelValue: '取消',
      cancel: function () {},
      ok: function () {
        var f = $('iframe', this.node);
        var v = $('form', f.contents()).serialize();
        console.log(v);
        $.post(url, v, function (resp, text, xhr) {
          console.log(resp);
          alert(resp.error);
          if (resp.errno == 0 || resp.errno == 110) {
            location.reload();
          }
        });
        return false;
      }
    }).showModal();
});
});
</script>
</form>
</body>
{/block}